package service

import (
	"context"
	"fmt"
	__ "user-srv/basic/proto"
	"user-srv/handler/dao"
)

// 会员添加
func (s *Server) MemberAdd(_ context.Context, in *__.MemberAddReq) (*__.MemberAddResp, error) {
	add, err := dao.MemberAdd(in)
	if err != nil {
		return nil, fmt.Errorf(err.Error())
	}

	return &__.MemberAddResp{
		Id: add.Id,
	}, nil
}

// 用户会员详情
func (s *Server) MemberDetails(_ context.Context, in *__.MemberDetailsReq) (*__.MemberDetailsResp, error) {
	details, err := dao.MemberDetails(in)
	if err != nil {
		return nil, fmt.Errorf(err.Error())
	}

	joinTime := details.JoinTime.Format("2006-01-02")
	overTime := details.OverTime.Format("2006-01-02")

	return &__.MemberDetailsResp{
		Id:          details.Id,
		UserId:      details.UserId,
		MemberNo:    details.MemberNo,
		LeveId:      details.LeveId,
		TotalPoints: details.TotalPoints,
		JoinTime:    joinTime,
		OverTime:    overTime,
		Status:      details.Status,
	}, nil
}
